package com.onemile.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import android.R.integer;

public class UtiData
{
   /**
    * 复制对象obj，类似于值传递，非引用
    */
   public static Object cloneObject(Object obj) throws Exception
   {
	  ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
	  ObjectOutputStream out = new ObjectOutputStream(byteOut);
	  out.writeObject(obj);
	  ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
	  ObjectInputStream in = new ObjectInputStream(byteIn);
	  return in.readObject();
   }

   /**
    * 保留小数
    * @param f 原始值
    * @param points 需要保留的小数位数
    * @return
    */
   public static float ToDecimal(float f, int points)
   {
	  try
	  {
		 int i=(int)Math.pow(10,points);
		 return (float)(Math.round(f * i)) / i;
	  }
	  catch (Exception e)
	  {
		
	  }
	  return 0;
   }
}
